/**
 * <pre>
 * Title: 		AbstractEntity.java
 * Author:		linriqing
 * Create:	 	2010-7-6 上午11:40:21
 * Copyright: 	Copyright (c) 2010
 * Company:		Shenzhen Helper
 * <pre>
 */
package com.hengpeng.common.persist.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.hengpeng.common.persist.OperateLogListener;
import com.hengpeng.common.web.annotation.HtmlInput;
import com.hengpeng.common.web.annotation.HtmlInputType;

/**
 * <pre>
 * 基类
 * </pre>
 * @author linriqing
 * @version 1.0, 2010-7-6
 */
@MappedSuperclass
@Inheritance(strategy = InheritanceType.JOINED)
@EntityListeners(OperateLogListener.class)
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
public abstract class AbstractEntity implements Serializable
{
	public final static int SEQALLOCATIONSIZE=1000;
	public final static int SEQINITNUM=1;
	/**
	 * <pre>
	 * 通用的枚举类型(是,否)
	 * </pre>
	 * @author linriqing
	 * @version 1.0, 2010-7-19
	 */
	public static enum BoolValue
	{
		/**
		 * 否
		 */
		NO("否", false),
		/**
		 * 是
		 */
		YES("是", true);

		private String text;

		private Boolean value;

		BoolValue(String text, Boolean value)
		{
			this.text = text;
			this.value = value;
		}

		public String getText()
		{
			return text;
		}

		public Boolean getValue()
		{
			return value;
		}

		public void setText(String text)
		{
			this.text = text;
		}

		public void setValue(Boolean value)
		{
			this.value = value;
		}

		public static BoolValue valueOf(boolean value)
		{
			if (value)
			{
				return BoolValue.YES;
			}
			else
			{
				return BoolValue.NO;
			}
		}
	}

	/**
	 * <pre>
	 * 证件类型枚举
	 * </pre>
	 * @author linriqing
	 * @version 1.0, 2010-7-19
	 */
	public static enum IdCardType
	{
		/**
		 * 身份证
		 */
		IDCARD("身份证"),
		/**
		 * 护照
		 */
		PASSPORT("护照"),
		/**
		 * 军官证
		 */
		SOLDIERCARD("军官证"),
		/**
		 * 士兵证
		 */
		XSOLDIERCARD("士兵证"),
		/**
		 * 港澳台胞证
		 */
		HK2MACAU2TAICARD("港澳台胞证"),
		/**
		 * 其它证件
		 */
		OTHERCARD("其它证");
		private String text;

		IdCardType(String text)
		{
			this.text = text;
		}

		public String getText()
		{
			return text;
		}

		public void setText(String text)
		{
			this.text = text;
		}
	}

	private static final long serialVersionUID = 6757814772463743205L;

	@HtmlInput(type = HtmlInputType.HIDDEN)
	@Column(nullable = false)
	private Long version = 0L;

	public abstract Object getId();

	public Long getVersion()
	{
		return version;
	}

	public void setVersion(Long version)
	{
		this.version = version;
	}

	public String toString()
	{
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
}
